package com.cjzuji.rental.dao.impl;

import com.cjzuji.rental.dao.LingLUserDao;
import com.cjzuji.rental.mapper.OrderUserMapper;
import com.cjzuji.rental.pojo.OrderUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;
@Service
public class LingLUserDaoImpl implements LingLUserDao {

    private static final Logger logger = LoggerFactory.getLogger(LingLUserDaoImpl.class);
    @Autowired
    OrderUserMapper orderUserMapper;

    @Override
    @Transactional
    public  void save(Map<String,Object> detail, Long orderID) {
        String userName = "";
        if (detail.get("realName") != null){
            userName = detail.get("realName").toString();
        }
        OrderUser lingLOrderUser = OrderUser.builder()
                .orderId(orderID)
                .userName(userName)  //收货人
                //.mobile(detail.get("phoneNum").toString())
                .province(" ")
                .city(" ")
                .county(" ")
                .address(" ")
                .addressInfo(removeEmoji(detail.get("address").toString()))
                .idCard(detail.get("idCard").toString())
                .idCardName(userName)
                .idCardImg(" ")
                .idCardBlackImg(" ")
                .faceImg("")
                .createTime(new Date())
                .updateTime(new Date())
                .build();
        //logger.info("打印添加参数order_user {}",lingLOrderUser);
        try {
            orderUserMapper.insert(lingLOrderUser);
        }catch (Exception e){
            logger.info("订单用户添加错误" + e.getMessage());
            throw e; // 重新抛出，确保事务回滚
        }
    }
    public String removeEmoji(String input) {
        if (input == null) {
            return "";
        }
        return input.replaceAll("[^\\u0000-\\uFFFF]", "");
    }
}
